package com.ittx.dzt.meituan.service;

import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.meituan.constant.MeituanApiConstant;
import com.ittx.dzt.meituan.handler.AbstractBaseMeituanApiHandler;
import com.ittx.dzt.sys.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 获取快递公司列表
 * <p>
 * cy.carrierPlatform.download
 * /api/v1/gw/logistics/company/list(查询支持的物流公司列表) https://tscc.meituan.com/home/doc/bulkPurchasing/657
 * </p>
 *
 * @author wushixiong
 * @since 2022/5/6 16:23
 */
@Slf4j
@Service
public class MeituanCarrierSyncService extends AbstractBaseMeituanApiHandler<String> {
    @Override
    public String getMeituanMethod() {
        return MeituanApiConstant.CARRIER_DOWNLOAD;
    }

    @Override
    public String getHttpMethod() {
        return MeituanApiConstant.ApiHttpMethod.POST;
    }

    @Override
    public String getLocalApiMethod() {
        return open.constant.PlatformApiConstant.InboundInterface.CARRIER_PLATFORM_DOWNLOAD;
    }

    @Override
    public Result doProcess(PlatformApiParamDTO platformApiParamDTO, String s) {
        Map<String, String> params = new HashMap<>();
        params.put("poi_id", getPoIId(platformApiParamDTO));
        Result result = this.executeMeituanApi(platformApiParamDTO.getStoreConfig(), params, platformApiParamDTO.getRequestId());
        if (!result.isSuccess()) {
            return result;
        }
        Map<String, Object> resultMap = (Map<String, Object>) result.getData();
        // List<Map<String, Object>> dataMap = (List<Map<String, Object>>) resultMap.get(DATA_FIELD);
        return this.sendRequestToPlatform(platformApiParamDTO, resultMap, true);
    }
}
